package cbbx_sm.utils;

import java.io.IOException;
import java.util.List;

import cbbx_sm.parser.CameraData;
import cbbx_sm.parser.Frame;
import cbbx_sm.parser.Parser;

public class CameraDataFixer {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		int camId = 13;
		CameraData cameraData =
			Parser.parseFile("data/cameraData/20090527"+camId+".txt", String.valueOf(camId+""));

		fixCameraData(cameraData);
		
		System.out.println(cameraData.getNumberOfFrameWithBoundingBoxes());
	}

	public static void fixCameraData(CameraData cameraData) {
		List<Frame> camFrames = cameraData.getFrames();
		for (int i=1; i<camFrames.size(); i++) {
			// If previous frame contained a bounding box and current didn't.
			if (camFrames.get(i-1).getEntities().size() > 0
			&& camFrames.get(i).getEntities().size() == 0
			&& Timestamp.getNextTimeStamp(camFrames.get(i-1).getTimestamp())
			    .compareTo(camFrames.get(i).getTimestamp())==0) {
				camFrames.get(i).setEntities(camFrames.get(i-1).getEntities());
			}
		}		
	}

}
